package com.gxa.day2022_07_29_21.homework.others.log;

/**
 * @Description:
 * @Author: zhuiyi
 * @CreatTime: 2022/7/30 19:20
 **/
public class User implements Comparable<User>{

    private int id;
    private String name;
    private int age;
    private String password;

    public User(String name, String password) {
        this.name = name;
        this.password = password;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

//        if (id != user.id) return false;
//        if (age != user.age) return false;
//        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        return password != null && name!=null? password.equals(user.password) && name.equals(user.name): user.password == null && user.name==null;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + age;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        return result;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User(int id, String name, int age, String password) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.password = password;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return id+"\t" + name + "\t" + age + "\n";
    }

    public User() {
    }

    public User(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(User o) {
        //每个对象按照年龄 顺序排序
        return this.age - o.age;
    }


}
